<?php

namespace App\Http\Controllers;
use App\Models\FhCategory;
use App\Models\FhSetting;
use App\Models\FhNews;
use App\Models\FhPage;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function getWeb(){
        $data = FhSetting::first();
        return $data;
    }

    public function getNews(){
        $news = [];
        $data = FhSetting::where('id',1)->value('index_num');
        $news['fong'] = FhNews::where('show',1)->whereIn('type',[1,3])->orderby("created_at",'desc')->select('title','created_at','url')->limit($data)->get();
        $news['hot'] =  FhNews::where('show',1)->where('type',2)->orderby("created_at",'desc')->select('title','created_at','url')->limit($data)->get();
        return $news;
    }

    public function getcate($array,$pid,$level=0){
        $array[$level] = FhCategory::where('id',$pid)->select('c_name','c_url','pid')->first();
        if($array[$level]->pid==0){
            return $array;
        } 
        return $this->getcate($array,$array[$level]->pid, $level+1);
    }

    public function getBanners($url){
        $info = FhPage::where("url",'like',$url."%")->value('banner');
        return $info;
    }
}
